function fetchAlbums() {
    var req = opensocial.newDataRequest();
    var idspec = opensocial.newIdSpec({
        'userId': 'VIEWER',
        'groupId': 'SELF'
    });

    req.add(req.newFetchAlbumsRequest(idspec), 'viewerAlbums');
    //alert('Bommm!');
    req.send(fetchAlbumsHandler);
};

// Callback function, executed when orkut finishes fetching the viewer's
// public albums
function fetchAlbumsHandler(resp) {
//alert('Bommm! albuns handler');
    var viewerAlbumsResp = resp.get('viewerAlbums');

    if (!viewerAlbumsResp.hadError()) {
        var viewerAlbums = viewerAlbumsResp.getData();

        viewerAlbums.each(
        function (album) {
            createPhotosRow(album);
        });
    }
	
};

function createPhotosRow(album) {
//alert('Bommm! photos row');
    var req = opensocial.newDataRequest();
    var idspec = opensocial.newIdSpec({
        'userId': 'VIEWER',
        'groupId': 'SELF'
    });
    req.add(req.newFetchMediaItemsRequest(idspec, album.getId()), 'albumPhotos1');
    req.send(fetchPhotosLine);
}

var urls = '';

function fetchPhotosLine(resp) {
    //alert('Bommm! photos line');
    var albumPhotosResp = resp.get('albumPhotos1');

    if (!albumPhotosResp.hadError()) {
        var albumPhotos = albumPhotosResp.getData();
        media = albumPhotos;
        
		var primeiro = true;
		
		//each photo in album
        albumPhotos.each(
			function (photo) {
				
				if (!primeiro){
					urls = urls + '///' + photo.getThumbnailUrl();
				}
				else {
					urls = urls + photo.getThumbnailUrl();
					primeiro = false;
				}
				
			});
    }
};

function getPhotoUrls() {
//alert('Bommm! photo urls');
	return urls;
}